package com.lin.manager.pay.config;

import com.lin.manager.pay.config.properties.PayProperties;
import com.lin.manager.pay.service.AliPayService;
import com.lin.manager.pay.service.Pay;
import com.lin.manager.pay.service.PayService;
import com.lin.manager.pay.service.WxPayService;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @作者: 林江
 * @创建时间: 2024/4/21
 * @功能:
 */
@EnableConfigurationProperties(PayProperties.class)
public class PayConfig {

    @Bean
    public PayService payService(PayProperties properties) {
        Map<String, Pay> map = new ConcurrentHashMap<>();

        // 支付宝
        AliPayService aliPayService = new AliPayService(properties.getAliPay());
        map.put(aliPayService.getName(), aliPayService);

        // 微信
        WxPayService wxPayService = new WxPayService(properties.getWxPay());
        map.put(wxPayService.getName(), wxPayService);

        PayService service = new PayService();
        service.setPayMap(map);
        return service;
    }

}
